package com.ivan.eduservice.controller;

import com.ivan.commonutils.CommonResult;
import com.ivan.eduservice.entity.node.SubjectNode;
import com.ivan.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Ivan
 * @since 2020-08-08
 */
@Api("课程管理")
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    /**
     * @Author Ivan
     * @Description 添加课程分类
     * 获取上传过来文件，把文件内容读取出来
     * @Date 2020/8/8 14:17
     * @Param
     * @return
     */
    @ApiOperation(value = "添加课程分类")
    @PostMapping("addSubject")
    public CommonResult addSubject(MultipartFile file) {
        //上传过来excel文件
        subjectService.saveSubject(file, subjectService);
        return CommonResult.success();
    }

    /**
     * @Author Ivan
     * @Description 获取课程分类列表（树形结构）
     * @Date 2020/8/8 19:10
     * @Param
     * @return
     */
    @ApiOperation(value = "获取课程分类列表")
    @GetMapping("getAllSubject")
    public CommonResult getAllSubject() {
        //list集合泛型是一级分类+二级分类
        List<SubjectNode> list = subjectService.getAllSubjectNodes();
        return CommonResult.success().data("list",list);
    }
}

